package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.*;
import com.macro.mall.model.BmsMuseumApplicant;
import com.macro.mall.portal.service.BmsMuseumApplicantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(tags = "BmsMuseumApplicantController")
@Tag(name = "BmsMuseumApplicantController", description = "文博项目-报名")
@RequestMapping("/museumApplicant")
public class BmsMuseumApplicantController {

    @Autowired
    private BmsMuseumApplicantService bmsMuseumApplicantService;

    @ApiOperation("分页查询文博项目-报名")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsMuseumApplicant>> getList(@RequestBody BmsMuseumApplicantParam bmsMuseumApplicantParam) {
        List<BmsMuseumApplicant> bmsMuseumApplicantList = bmsMuseumApplicantService.getList(bmsMuseumApplicantParam);
        return CommonResult.success(CommonPage.restPage(bmsMuseumApplicantList));
    }

    @ApiOperation("根据id获取文博项目-报名信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsMuseumApplicantDetail> getItem(@PathVariable Long id) {
        BmsMuseumApplicantDetail bmsMuseumApplicantDetail = bmsMuseumApplicantService.getItem(id);
        return CommonResult.success(bmsMuseumApplicantDetail);
    }

    @ApiOperation("活动预约报名")
    @RequestMapping(value = "/activitiesRegistration", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<String> activitiesRegistration(@RequestBody ActivitiesRegistrationParam activitiesRegistrationParam) {
        ActivitiesRegistrationResult activitiesRegistrationResult = bmsMuseumApplicantService.activitiesRegistration(activitiesRegistrationParam);
        if (activitiesRegistrationResult.getCode().equals("500")) {
            return CommonResult.failed(activitiesRegistrationResult.getMessage());
        }
        return CommonResult.success(activitiesRegistrationResult.getMessage());
    }


    @ApiOperation("活动预约报名")
    @RequestMapping(value = "/activitiesCancel", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<String> activitiesCancel(@RequestBody ActivitiesRegistrationParam activitiesRegistrationParam) {
        ActivitiesRegistrationResult activitiesRegistrationResult = bmsMuseumApplicantService.activitiesCancel(activitiesRegistrationParam);
        if (activitiesRegistrationResult.getCode().equals("500")) {
            return CommonResult.failed(activitiesRegistrationResult.getMessage());
        }
        return CommonResult.success(activitiesRegistrationResult.getMessage());
    }
}
